import { View } from "../../../../mvc/core/View";
import { Language } from "../../../../../extend/language/Language";
import { LayerManager } from "../../../manager/LayerManager";
import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { MagicTowerInfoTitle } from "./MagicTowerInfoTitle";
import { TowerInfoHideButton } from "./TowerInfoHideButton";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { TowerPassConditionPanel } from "./TowerPassConditionPanel";
import { TowerPassRewardsPanel } from "./TowerPassRewardsPanel";
import { Cache } from "../../../cache/Cache";
import { MagicTowerConfig } from "../../../resource/MagicTowerConfig";
import { CopyConfig } from "../../../resource/CopyConfig";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SceneRange } from "../../../scene/map/SceneRange";
import { Global } from "../../../../../com/gengine/global/Global";
import { TweenMax } from "../../../../../com/greensock/TweenMax";
import { Quint } from "../../../../../com/greensock/easing/Quint";
import { TaskCache } from "../../../cache/TaskCache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class MagicTowerInfoPanel
    
    export  class MagicTowerInfoPanel extends View
    {
        constructor()
        {
            super();
            this._infoTabData = Language.getArray(60067);
            this._moveRec = new Object /* flash.geom.Rectangle */();
            this.mouseEnabled = false;
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            this._bodySp = new Object /* flash.display.Sprite */();
            this._bodySp.mouseEnabled = false;
            this.addChild(this._bodySp);
            this._moveBtn = ObjCreate.createGButton("", 0, 0, 24, 22, this._bodySp, "MoveBtn");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(60068), "#FFFFFF");
            this._titleSp = new MagicTowerInfoTitle();
            this._titleSp.x = 24;
            this._titleSp.y = -4;
            this._titleSp.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._bodySp.addChild(this._titleSp);
            this._zoomBtn = new TowerInfoHideButton();
            this._zoomBtn.x = 248;
            this._zoomBtn.y = 11;
            this.addChild(this._zoomBtn);
            this._zoomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onZoomBtnClick);
            this.showPanelByIndex(0);
            return;
        }

        /* internal  */onTabBarChangeHandler(arg1: MuiEvent): void
        {
            this.showPanelByIndex(arg1.selectedIndex);
            return;
        }

        public showPanelByIndex(arg1: int): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case 0:
                {
                    if (!this._conditionPanel) 
                    {
                        this._conditionPanel = new TowerPassConditionPanel();
                        this._conditionPanel.x = 0;
                        this._conditionPanel.y = 22;
                        this._bodySp.addChild(this._conditionPanel);
                    }
                    this._conditionPanel.visible = true;
                    if (this._rewardsPanel) 
                    {
                        this._rewardsPanel.visible = false;
                    }
                    break;
                }
                case 1:
                {
                    if (!this._rewardsPanel) 
                    {
                        this._rewardsPanel = new TowerPassRewardsPanel();
                        this._rewardsPanel.x = 0;
                        this._rewardsPanel.y = 22;
                        this._bodySp.addChild(this._rewardsPanel);
                    }
                    this._rewardsPanel.visible = true;
                    if (this._conditionPanel) 
                    {
                        this._conditionPanel.visible = false;
                    }
                    break;
                }
            }
            return;
        }

        public updateInfos(arg1: Boolean): void
        {
            var loc1=Cache.instance.copy.magicTowerInfo;
            var loc2=loc1 ? MagicTowerConfig.instance.getInfoByFloor(loc1.floor) : null;
            var loc3=loc2 ? CopyConfig.instance.getInfoByCode(loc2.copyCode) : null;
            if (loc1 && loc2 && loc3) 
            {
                if (loc1.floor <= 0) 
                {
                    this._titleSp.title = HTMLUtil.addColor(loc3.name + Language.getString(60071), GlobalStyle.color2);
                }
                else 
                {
                    this._titleSp.title = HTMLUtil.addColor(loc3.name + Language.getStringByParam(60072, "<font face=\'" + FontUtil.stXingkaiName + "\'>  " + HTMLUtil.addColor(loc2.realFloor + "  </font>", "#FFFF00")), GlobalStyle.color2);
                }
                this._conditionPanel.updateInfos(loc1, loc2, loc3, arg1);
            }
            else 
            {
                this._conditionPanel.clear();
                this._titleSp.title = "";
            }
            return;
        }

        /* internal  */onZoomBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._zoomBtn.show) 
            {
                this.hidePanel();
            }
            else 
            {
                this.showPanel();
            }
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._moveRec.x = 0;
            this._moveRec.y = 0;
            this._moveRec.width = SceneRange.display.width - 30;
            this._moveRec.height = SceneRange.display.height - 30;
            startDrag(false, this._moveRec);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public updatePosition(): void
        {
            if (this._zoomBtn.show) 
            {
                x = SceneRange.display.width - 284;
                y = 180 + 20 * SceneRange.display.height / 1000;
            }
            else 
            {
                x = SceneRange.display.width - 260;
                y = 288;
            }
            return;
        }

        public updateStatus(arg1: string): void
        {
            if (arg1 != MagicTowerInfoPanel.Expand) 
            {
                if (arg1 == MagicTowerInfoPanel.Shrink) 
                {
                    this._zoomBtn.show = false;
                    if (this._bodySp.parent) 
                    {
                        removeChild(this._bodySp);
                    }
                }
            }
            else 
            {
                this._zoomBtn.show = true;
                if (!this._bodySp.parent) 
                {
                    addChild(this._bodySp);
                }
            }
            return;
        }

        public hidePanel(): void
        {
            if (this._showTween && this._showTween.active) 
            {
                this._showTween.kill();
            }
            x = SceneRange.display.width - 260;
            y = 288;
            this._hideTween = TweenMax.to(this._bodySp, 0.2, {"x": 260, "ease": Quint.easeOut, "onComplete": this.onHideEnd});
            this._zoomBtn.show = false;
            return;
        }

        /* internal  */onHideEnd(): void
        {
            if (this._bodySp.parent) 
            {
                removeChild(this._bodySp);
            }
            return;
        }

        public showPanel(): void
        {
            if (TaskCache.showTrack) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            }
            if (this._hideTween && this._hideTween.active) 
            {
                this._hideTween.kill();
            }
            x = SceneRange.display.width - 284;
            y = 180 + 20 * SceneRange.display.height / 1000;
            this._showTween = TweenMax.to(this._bodySp, 0.2, {"x": 0, "ease": Quint.easeIn});
            this._zoomBtn.show = true;
            if (!this._bodySp.parent) 
            {
                addChild(this._bodySp);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            Dispatcher.addEventListener(EventName.TrackClick, this.onTaskTrackClick);
            return;
        }

        /* internal  */onTaskTrackClick(arg1: DataEvent): void
        {
            if (arg1.data && this._zoomBtn.show) 
            {
                this.hidePanel();
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.removeEventListener(EventName.TrackClick, this.onTaskTrackClick);
            return;
        }

        /* internal */ /* var */_infoTabData: Array<any>;

        /* internal */ /* var */_moveRec: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_hideTween: TweenMax;

        /* internal */ /* var */_showTween: TweenMax;

        protected /* var */_bodySp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_moveBtn: GButton;

        protected /* var */_titleSp: MagicTowerInfoTitle;

        /* internal */ /* var */_zoomBtn: TowerInfoHideButton;

        /* internal */ /* var */_conditionPanel: TowerPassConditionPanel;

        /* internal */ /* var */_rewardsPanel: TowerPassRewardsPanel;

        public static /* var */Expand: string="伸展";

        public static /* var */Shrink: string="收缩";
    }

            MagicTowerInfoPanel.Expand = "伸展";
            MagicTowerInfoPanel.Shrink = "收缩";
        